package br.com.fpf.pontoapp.ws.impl;

import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

/**
 * The Class ParsePonto.
 * 
 * @author irlan.gomes
 */
class ParsePonto {

	/** The user name. */
	private String userName;

	/** The work day. */
	private String workDay;

	/** The beats point. */
	private List<String> beatsPoint = new ArrayList<String>();

	/**
	 * Parses the.
	 * 
	 * @param html
	 *            the html
	 */
	public void parse(String html) {

		Document docSoup = Jsoup.parse(html);

		String name = getName(docSoup.select("div.float_r").text());
		Elements body = docSoup.select("tbody tr");

		userName = name;
		for (int i = 0; i < 31; i++) {
			Elements row = body.get(i).select("td[rowspan]");

			String day = row.get(0).text();
			String hours = row.get(2).text();

			workDay = day;
			beatsPoint.add(hours);
		}

	}

	/**
	 * Gets the user name.
	 * 
	 * @return the user name
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * Gets the work day.
	 * 
	 * @return the work day
	 */
	public String getWorkDay() {
		return workDay;
	}

	/**
	 * Gets the beats point.
	 * 
	 * @return the beats point
	 */
	public List<String> getBeatsPoint() {
		return beatsPoint;
	}

	/**
	 * Gets the name.
	 * 
	 * @param text
	 *            the text
	 * @return the name
	 */
	private static String getName(String text) {
		int pos = text.indexOf(" | Imprimir | sair");
		return text.substring(0, pos);
	}

}
